package com.project.controller;

import com.project.bean.UserBean;
import com.project.util.MultipartFileUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLDecoder;

@RestController
@RequestMapping("user")//别名自己取
//类名记着自己改一下
public class UserController {

    @RequestMapping("add")
    public String add(UserBean userBean, @RequestParam("face") MultipartFile mt) throws IOException {
        userBean.setImg(MultipartFileUtil.play(mt,"static/html/userImg"));
        System.out.println(userBean);
        return "ok";
    }

    @RequestMapping("land")
    public String land(String userName, String pwd, HttpServletRequest request){
        if ("java".equalsIgnoreCase(userName)&&"123".equals(pwd)){
            request.getSession().setAttribute("loginUser","java");
            return "ok";
        }
        return "no";
    }

    @RequestMapping("test")
    public String test(HttpServletRequest request){
        String name=request.getParameter("name");
        return name;
    }
}